//package com.fecean.aabbc.netty.client.prod2;
//
//import com.fecean.aabbc.netty.message2.NettyMessageBuilder;
//import io.netty.channel.ChannelHandler;
//import io.netty.channel.ChannelHandlerContext;
//import io.netty.channel.ChannelInboundHandlerAdapter;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//
///**
// * NettyServerHeartBeatHandler
// *
// * @author: chenfenghai
// * @version: 1.0
// * @date: 2020-03-05 15:59
// * @blame Team
// */
//@Slf4j
//@Component
//@ChannelHandler.Sharable
//public class NettyClientRegisterHandler extends ChannelInboundHandlerAdapter {
//
//    @Resource
//    NettyClientChannel nettyClientChannel;
//
//    /**
//     ** 影院配置
//     */
//    @Resource
//    CinemaConfig cinemaConfig;
//
//    @Override
//    public void channelActive(ChannelHandlerContext ctx) {
//        log.info("客户端[{}-{}]连接成功", cinemaConfig.getTenantId(), cinemaConfig.getCinemaCode());
//        ctx.writeAndFlush(NettyMessageBuilder.buildRegisterMessage(
//                cinemaConfig.getTenantId(),
//                cinemaConfig.getCinemaCode()));
//        ctx.fireChannelActive();
//    }
//
//    @Override
//    public void channelRead(ChannelHandlerContext ctx, Object msg) {
//        NettyMessageBuilder messageBuilder = NettyMessageBuilder.readMessage(msg);
//        if(messageBuilder.isRegisterMessage()){
//            nettyClientChannel.setChannel(ctx.channel());
//            log.info("客户端[{}-{}]注册成功",
//                    messageBuilder.getNettyMessage().getTenantId(),
//                    messageBuilder.getNettyMessage().getCinemaCode());
//        }else{
//            ctx.fireChannelRead(msg);
//        }
//    }
//
//    @Override
//    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
//        nettyClientChannel.clear();
//        ctx.fireChannelInactive();
//    }
//}
